<template>
  <div class="outMore">
    <el-form :inline="true" class="demo-form-inline">
      <el-dialog
        title="提示"
        :visible.sync="dialogDisableTop"
        width="540px"
        class="sendingDisableDialog"
        style="margin-top: 20vh;">
        <div style="width: 100%; text-align: center; height: 100px; padding-top: 35px;">
          <img :src="disableIcon"/>
        </div>
        <span>确认批量禁用策略</span>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogDisableTop = false">取 消</el-button>
          <el-button type="primary" style="float: right" @click="showDisable()">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="dialogEnableTop"
        width="540px"
        class="sendingDisableDialog"
        style="margin-top: 20vh;">
        <div style="width: 100%; text-align: center; height: 100px; padding-top: 35px;">
          <img :src="enableIcon"/>
        </div>
        <span>确认批量启用策略</span>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogEnableTop = false">取 消</el-button>
          <el-button type="primary" style="float: right" @click="showEnable()">确 定</el-button>
        </span>
      </el-dialog>
      <el-form-item class="handItem" label="告警发送策略列表">
        <el-input class="searchInput" v-model="searchNeed"></el-input><i @click="searchWork" class="el-icon-search search"></i>
        <el-button v-show="returnShow" class="indieWidth Batchdisable" type="primary" @click="outlineWork">
          重置
        </el-button>
      </el-form-item>
      <el-form-item class="handItem" style="float: right">
        <el-button class="indieWidth" type="primary" @click="realTimeStrategy()">
          <img :src="addsite"/>新增实时策略
        </el-button>
        <el-button class="indieWidth" type="primary" @click="timingStrategy()">
          <img :src="addsite"/>新增定时策略
        </el-button>
        <el-button type="primary" class="clear" @click="sendingDeleteAll()">
          <img :src="whitedelete"/>批量删除
        </el-button>
        <el-button class="indieWidth" type="primary" @click="showEnableDialog">
          <img :src="whiteenable"/>批量启用
        </el-button>
        <el-button class="indieWidth Batchdisable" type="primary" @click="showDisableDialog">
          <img :src="whitedisable"/>批量禁用
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import addsite from '@/assets/mSiteAdmin/add.png'
  import whitedelete from '@/assets/mSiteAdmin/whitedelete.png'
  import whiteenable from '@/assets/mSiteAdmin/whiteenable.png'
  import whitedisable from '@/assets/mSiteAdmin/whitedisable.png'
  import enableIcon from '@/assets/mSiteAdmin/enable-icon.png'
  import disableIcon from '@/assets/mSiteAdmin/disable-icon.png'
  import axios from 'axios'
  export default {
    props: ['deleteStrategys'],
    data() {
      return {
        addsite,
        whitedelete,
        whiteenable,
        whitedisable,
        enableIcon,
        disableIcon,
        dialogDisableTop: false,
        dialogEnableTop: false,
        showData: {
          realTime: false,
          timing: false,
          sending: false
        },
        returnShow: false,
        searchNeed: '',
        // 删除告警策略
        deleteStrategyBody: {
          access_token: localStorage.getItem('access_token'),
          type: 'strategy_del',
          pid: localStorage.getItem('num'),
          ids: []
        },
        // 启用告警策略
        strategyEnable: {
          access_token: localStorage.getItem('access_token'),
          type: 'strategy_enable',
          pid: localStorage.getItem('num'),
          ids: []
        },
        // 禁用告警策略
        strategyDisable: {
          access_token: localStorage.getItem('access_token'),
          type: 'strategy_disable',
          pid: localStorage.getItem('num'),
          ids: []
        }
      }
    },
    methods: {
      realTimeStrategy() {
        this.showData.timing = false
        this.showData.sending = false
        this.showData.realTime = true
        this.$emit('needShowData', this.showData)
      },
      timingStrategy() {
        this.showData.realTime = false
        this.showData.sending = false
        this.showData.timing = true
        this.$emit('needShowData', this.showData)
      },
      // 删除按钮事件
      sendingDeleteAll() {
        if (this.deleteStrategys.length === 0) {
          this.$message({
            showClose: true,
            message: '请勾选要批量删除的策略！',
            type: 'error'
          })
        } else {
          this.$confirm('确认批量删除发送策略？', '提示', {
            cancelButtonClass: 'userCancel',
            confirmButtonClass: 'userConfirm',
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.deleteAllDo()
          }).catch(() => {
          })
        }
      },
      // 多个删除
      deleteAllDo() {
        this.deleteStrategyBody.ids = this.deleteStrategys
        let httpStr = process.env.SERVER_URL_ALARM_SERVICE
        axios.post(httpStr + '/strategy', this.deleteStrategyBody, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.showData.realTime = false
          this.showData.sending = true
          this.showData.timing = false
          this.deleteStrategyBody.ids = []
          this.$message({
            type: 'success',
            message: '删除成功'
          })
          this.$emit('needShowData', this.showData)
        })
          .catch((error) => {
            this.$message.error(error.data.errmsg)
          })
      },
      showEnableDialog() {
        if (this.deleteStrategys.length === 0) {
          this.$message({
            showClose: true,
            message: '请勾选要批量启用的策略！',
            type: 'error'
          })
        } else {
          this.strategyEnable.ids = this.deleteStrategys
          this.dialogEnableTop = true
        }
      },
      showEnable(index, row) {
        let httpStr = process.env.SERVER_URL_ALARM_SERVICE
        axios.post(httpStr + '/strategy', this.strategyEnable, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.strategyEnable.ids = []
          this.dialogEnableTop = false
          this.showData.realTime = false
          this.showData.sending = true
          this.showData.timing = false
          this.$emit('needShowData', this.showData)
        })
          .catch(function(error) {
            console.log(error)
          })
      },
      // 禁用
      showDisableDialog() {
        if (this.deleteStrategys.length === 0) {
          this.$message({
            showClose: true,
            message: '请勾选要批量禁用的策略！',
            type: 'error'
          })
        } else {
          this.strategyDisable.ids = this.deleteStrategys
          this.dialogDisableTop = true
        }
      },
      showDisable(index, row) {
        let httpStr = process.env.SERVER_URL_ALARM_SERVICE
        axios.post(httpStr + '/strategy', this.strategyDisable, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.strategyDisable.ids = []
          this.dialogDisableTop = false
          this.showData.realTime = false
          this.showData.sending = true
          this.showData.timing = false
          this.$emit('needShowData', this.showData)
        })
          .catch(function(error) {
            console.log(error)
          })
      },
      // 搜索
      searchWork() {
        if (this.searchNeed === '') {
          this.$message({
            message: '请输入安全策略名称!',
            type: 'warning'
          })
        } else {
          this.returnShow = true
          this.$emit('strategySearch', this.searchNeed)
        }
      },
      // 重置搜索
      outlineWork() {
        this.returnShow = false
        this.searchNeed = ''
        this.$emit('strategySearch', this.searchNeed)
      }
    }
  }
</script>
<style scoped>
  .outMore{
    width: 100%;
    height: 50px;
    background-color: #ffffff;
    padding-top: 5px;
    padding-left: 20px;
    border-bottom: 1px solid #e0e0e0;
  }
  /deep/ .search{
    position: absolute;
    margin-top: 13px;
    margin-left: -30px;
    cursor: pointer;
    color: #0072F3;
    font-weight: 700;
  }
  .Batchdisable{
    background-color: #D05133 !important;
    border: 1px solid  #D05133 !important;
  }
  /deep/ label {
    font-weight: normal;
    color: #69727E;
  }
  /deep/ .handItem {
    margin-bottom: 5px!important;
  }
  /deep/ .indieWidth {
    padding: 6px 8px;
  }
  /deep/ .reset {
    padding: 6px 16px;
    background-color: #526D89;
    border-color: #526D89 ;
    color: #fff;
  }
  /deep/ .clear{
    padding: 6px 16px;
    background-color: #526D89;
    border-color: #526D89 ;
    color: #fff;
  }
  /deep/ .el-button + .el-button {
    margin-left: 5px;
  }
  /deep/ .el-button--primary {
    height: 30px;
    font-size: 14px;
    padding: 6px 16px;
    background: #0072F3;
    border-color: #0072F3;
  }
  /deep/ .el-input__inner {
    height: 30px;
    line-height: 30px;
    width: 360px;
  }
  /deep/ .clear{
    padding: 6px 16px;
    background-color: #333B3D;
    border-color: #333B3D ;
    color: #fff;
    line-height: 0px;
  }
  /deep/ .export {
    background: #fff;
    border: 1px solid #0072F3;
    color: #0072F3;
  }
  /deep/ .el-icon-delete {
    height: 16px;
    line-height: 12px;
  }
  /deep/ .el-icon-delete:before {
    font-size: 16px;
    color: #fff;
  }
  /deep/ .el-message-box{
    width: 540px;
  }
  /deep/ .el-message-box__header{
    background-color: #E3E6EE;
    padding: 10px 15px;
  }
  /deep/ .el-message-box__title{
    font-size: 18px;
    font-weight: Bold;
    color: #323842;
  }
  /deep/ .el-message-box__status{
    right: 247px;
    top: 65px;
    font-size: 48px !important;
  }
  /deep/ .el-message-box__status.el-icon-warning{
    color: #E53D41;
  }
  /deep/ .el-message-box__content{
    height: 182px;
  }
  /deep/ .el-message-box__message p {
    margin: 0;
    font-size: 18px;
    color: #323842;
    padding-top: 96px;
    text-indent: 0px;
    text-align: center;
  }
  /deep/ .el-message-box__headerbtn{
    top: 9px;
    font-size: 18px;
  }
  /deep/ .el-message-box__btns{
    padding: 10px 15px 7px ;
    border-top: 1px solid #e8eaf1;
  }
  /deep/ .dialogSafeAdd > .el-dialog > .el-dialog__body {
    padding: 0px;
  }
  /deep/ .dialogSafeAdd > .el-dialog > .el-dialog__footer {
    height: 50px;
  }
  /deep/ .el-dialog {
    width: 800px;
  }
  /deep/ .editForm {
    padding: 10px 20px;
    margin: 0px;
  }
  /deep/ .editRowLeft {
    background: #EAEDF1;
    border: 1px solid #E4E5E7;
    height: 499px;
  }
  /deep/ .notes {
    float: left;
    height: 30px;
    line-height: 30px;
    font-size: 14px;
    color: #69727E;
  }
  /deep/ #editAsterisk {
    color: #E53D41;
  }
  /deep/ .clears{
    padding: 6px 16px;
    background-color: #526D89;
    border-color: #526D89 ;
    color: #fff;
    float: right;
    margin-left: 10px;
  }
  /deep/ .bottonConfirm {
    padding: 6px 16px;
    float: right;
    border:1px solid #0072F3;
    background: #0072F3;
  }
  /deep/ .leftInput > .el-input__inner {
    height: 30px;
    margin:10px 20px;
    width: 220px;
  }
  .editSearch{
    position: absolute;
    margin-top: 18px;
    margin-left: -45px;
    cursor: pointer;
    color: #0072F3;
  }
  /deep/ .addEditIcon {
    color: #0072F3;
    font-size: 16px;
    cursor: pointer;
  }

  /deep/ .addSafeTable {
    height: 495px;
    overflow-y: auto;
  }
  /deep/ .addSafeTable > .el-table__header-wrapper{
    height: 0px;
  }
  /deep/ .addSafeTable > .el-table__body-wrapper > .el-table__body > tbody > .el-table__row > .el-table td, .el-table th{
    padding: 5px 0px;
  }
  /deep/ .el-icon-minus {
    color: #D05133;
  }
  /deep/ .timeInterval {
    height: 30px;
    width: 365px;
    float: right;
  }
  .searchInput {
    width: 365px;
  }
</style>
